
import java.util.Arrays;
import java.util.Date;
import java.util.List;



public class License {
	

	
	private static final int maxOrganisms = 18;
	// These boolean arrays tell you which values in the strings arrays are being
	// used
	private Boolean[] organismB;
	private Boolean[] microArrayB;
	private Boolean[] geneidB;
	private Boolean[] databaseB;
	private Boolean[] anaylsisB;
	private String macaddress;
	private Date expirationDate;
	
	// We can read in the list from another xml file??? more work
	// better code??
	private static String[] ORGANISM = {"Homo sapien", "Mus musculus", "Rattus novegicus",
						 "Arabidopsis thaliana (Thale cress)", "Drosophilla melanogaster (Fruit Fly)",
						 "Canis lupus familiaris (Dog)", "Danio rerio (Zebrafish)", 
						 "Caenorhabiditus elegans (Nematode)", "Gallus gallus (chicken)",
						 "Bos taurus (Cow/Bovine)", "Sus scrofa domesticus (Pig)"};
	private static String[] MICROARRAY = {"Affymatrix", "Applied Biosystems", "HitachiSoft", "Illumina",
			               "Invitrogen", "Miltenyl Biotech", "NimbleGen", "Agilent Technologies",
			               "Ocimum Biosolutions", "Operon", "Phalanx Biotech", "Rosetta Inpharmatics/Merck Parmaceuticals",
			               "Sigma Genosys", "SuperArray", "TORAY INDUSTRIES", "BD Bioscinces Clontech", "CapitalBio"};
	private static String[] GENEID = {"Entrez", "Gene Symbol", "GeneBank Accession", "GeneBank Gis",
			           "Ensemble", "Probe ID"};
	private static String[] PATHWAYDB = {"Reactome", "KEGG"};
	private static String[] ANALYSIS = {"DE Genes Impact Analysis",
					   "DE Genes Coherent Chains of Perturbation",
					   "All Genese Impact Analysis",
					   "All Genes with GSA & PADOG"};
	
	private static String[] lookupCombination = { "999" , "000" , "001" , "010" , "011" , "100" , "101" , "110" , "111" };
	private static List<String> lookupCombinationList = Arrays.asList ( lookupCombination );
	
// ------------------------------------------------------------------------------------------------------------------ 	
	
	private static int lookupCombinationID(String groupOfThree)
	{
		 int groupOfThreeID;
		 
		 groupOfThreeID = lookupCombinationList.indexOf(groupOfThree);
		 return groupOfThreeID;
	}

	
// ------------------------------------------------------------------------------------------------------------------ 	

	public static List getClientSelections()
	{
		// Test Case - some random Client Selections...
		String[] passedClientSelections = 
				{ "Homo sapien" , "Drosophilla melanogaster (Fruit Fly)" , "Gallus gallus (chicken)" ,
						"HitachiSoft" , "Operon" , "Applied Biosystems" ,
						"GeneBank Gis" , "Gene Symbol" , 
						"KEGG" ,
						"All Genes with GSA & PADOG" , "All Genese Impact Analysis" };
		
		 List<String> clientSelections = Arrays.asList ( passedClientSelections );
		 return clientSelections;
	}

// ------------------------------------------------------------------------------------------------------------------ 	
	
	private static String generateSuperSecretcode(List clientSelections)
	{
		// SuperSecretCode Format: Organism-MicroArray-GeneID&Database-Analysis&macAddress-macAddress-expDate
		String organismSecretId = "";
		String microArraySecretId = "";
		String geneidSecretId = "";
		String databaseISecretId = "";
		String analysisSecretId = "";
		String macaddressSecretId = "";
		String expirationDateID = "";
		
		int[] organismStatus = new int[maxOrganisms]; 
		
		int batchOfThree = 0;
		String groupOfThree = "";
		
		for ( int organismCounter = 0 ; organismCounter < (ORGANISM.length) ; organismCounter++ )
			{
				if ( clientSelections.contains( ORGANISM[organismCounter] ) )
					{
						organismStatus[organismCounter] = 1 ;
					}
				else
					{
						organismStatus[organismCounter] = 0 ;
					}
				
				System.out.println("Organism being checked is " + organismCounter + " and the value being added to the array is  : " + organismStatus[organismCounter]);
			}
		
		for ( int remainingOrganismCounter = ORGANISM.length + 1 ; remainingOrganismCounter < (maxOrganisms) ; remainingOrganismCounter++ )
			{
				organismStatus[remainingOrganismCounter] = 0 ;
			}
		
		
		for (int counter = 0 ; counter < maxOrganisms ; counter ++)
			{
				System.out.print(organismStatus[counter]);
			}
		
		System.out.println();
		
		for (int counter = 0 ; counter < maxOrganisms ; counter +=3)
			{
				groupOfThree += organismStatus[counter];
				groupOfThree += organismStatus[counter+1];
				groupOfThree += organismStatus[counter+2];
				System.out.println( groupOfThree + "is converted into a code of : " + lookupCombinationID(groupOfThree));
				System.out.println("-");
				groupOfThree = "";
				
			}
		
		/*
		for (String organismItem:ORGANISM)
			{
				if ( clientSelections.contains( organismItem ) )
					{
						groupOfThree += "1";
						System.out.println("Organism being checked is " + organismItem + " and it is in the clientSelections so the groupOfThree is now : " + groupOfThree);
					}
				else
					{
						groupOfThree += "0";
						System.out.println("Organism being checked is " + organismItem + " and it is NOT in the clientSelections so the groupOfThree is now : " + groupOfThree);
					}
				batchOfThree ++;
				if ( batchOfThree == 3 )
					{
						organismSecretId += lookupCombinationID(groupOfThree);
						batchOfThree = 0;
						groupOfThree = "";
					}
				
			}
		System.out.println("Organism is now equal to :" + organismSecretId);
		
		for ( int packLastBatch = batchOfThree ; packLastBatch > 1 ; packLastBatch-- )
			{
				groupOfThree += "0";
			}
		System.out.println( "Last Batch of Organish now equals " + groupOfThree );
*/		

		
		
		
		
		return null;
	}
	
	
	
// ------------------------------------------------------------------------------------------------------------------ 	
// ------------------------------------------------------------------------------------------------------------------ 	

	public static void main(String[] args)
	{
		List clientSelections;
		String clientSuperSecretCode;
		
		
		clientSelections = getClientSelections();
		clientSuperSecretCode = generateSuperSecretcode ( clientSelections );
//		showSuperSecretCode ( clientSuperSecretCode );
		
		
		
		
		
		
		/*		
		for (int counter = 0 ; counter < 9 ; counter++)
			{
				System.out.println(ORGANISM[counter]);
			}

		for (String items:ORGANISM)
			{
				System.out.println(items);
			}

		for (String lookupCode:lookupCombination)
			{
				System.out.println(lookupCode + " , " + lookupCombinationID(lookupCode));
			}
		 */
		
	}


}




